#include "serialport.h"

int main(void)
{
    uint8_t msg[16] = {0};
    sprintf((char*)msg, "0:hello, world");
    SerialPort serial_port("/dev/ydlidar", 115200);

    if(!serial_port.open())
        return 0;

    /* Start Io-service in Background, Run once */
    boost::thread([&](){serial_port.run_forever();});

    serial_port.close();
    if(!serial_port.open())
        return 0;

    for(int i=0;i<10000;i++)
    {
        msg[0] = i;
        std::vector<uint8_t> data((uint8_t *)msg, (uint8_t *)msg+sizeof(msg));
        serial_port.write(data);
    }
    
    std::cout << "Send Finish" << std::endl;
    getchar();
    std::cout << "Serial Port Totally Send: " << sizeof(msg)*10000 << ", Totally Receive: " << serial_port.total_recvbytes << std::endl;
    serial_port.close();

    sleep(1);
    return 0;
}